package csdn.jihe.li06;

public class Student implements Comparable<Student>{
    private String name;
    private int age;
    private String sex;
    
    public Student() {
    }
    public Student(String name, int age, String sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public String getSex() {
        return sex;
    }
    public void setSex(String sex) {
        this.sex = sex;
    }
    @Override
    public String toString() {
        return "\nStudent [name=" + name + ", age=" + age + ", sex=" + sex + "]";
    }
    @Override
    public int compareTo(Student o) {
        //重写的自然排序方法
        //name
        int num;
        num=this.name.compareTo(o.name);//调用String类的compareTo
        if(num==0){
            //name相同
            //ages升序排
            num=o.age-this.age;
            if(num==0){
                //age也相同
                //sex
                num=this.sex.compareTo(o.sex);
            }
        }
        return num;

      //  return this.age - o.age;  // 按年龄升序
    }
}

    

